/**
 * Created by sunyan on 2017/7/20.
 */
import gBarChart from "../../../../public_components/g_bar_chart"
function barChartData(ele,url,para,title){
  $.ajax({url:url,
    type:"get",
    data:para,
    dataType:"json"
  }).then((res) => {
    if(!res){
      console.log('没有barChart数据',url)
      return
    }
    var data = res.data;
    var newData = [];

    for(var k = 0; k<data.length; k++){
      var name = data[k].name;
      if(name.length>8){
        name = name.substring(0,10)+'...';
      }
      newData.push({
        name:name,
        barPercent:data[k].barPercent,
        percent:data[k].percent
      })
    }
    gBarChart(ele,{
      title: title,
      lists:newData,
      isIE9:isIE9()
    },false)
  }).then(function () {
    window.config.promiseStep++;
    console.log('加1了+'+url)
  })
}
/**
 *
 *判断是否是ie9
 *
 ** */
function isIE9(){
  let userAgent = navigator.userAgent;
  if(userAgent.indexOf("MSIE")>0 && userAgent.indexOf("MSIE 9.0")>0) {
    return true
  }else{
    return false
  }
}
module.exports={
  barChartData
}
